import alertYY from "../alertY/alertY.vue"

let $vmAlert;

export const alertY = {
  install(Vue){

    if (!$vmAlert) {
      const Alert = Vue.extend(alertYY)
      $vmAlert = new Alert({
        el: document.createElement('div')
      })
      document.body.appendChild($vmAlert.$el)
    }

    Vue.prototype._alertY = {
      showAlert(options = {}){
        $vmAlert.buttons = options.buttons || ["取消", "确认"];
        $vmAlert.content = options.content || "";
        if (options.prompt) {
          $vmAlert.prompt = options.prompt;
          $vmAlert.placeholder = options.placeholder || "";
        }
        this.show();
        // 组件按钮点击回调
        $vmAlert.$off('btnCall');
        $vmAlert.$on('btnCall', v => {
          this.hide();
          options.onTap && options.onTap(v)
        })
      },
      hide(){
        $vmAlert.alertShow = false;
        setTimeout(() => {
          $vmAlert.show = false;
        }, 300);
      },
      show(){
        $vmAlert.show = true;
        setTimeout(() => {
          $vmAlert.alertShow = true;
        }, 20);
      }
    }
  }
}
/*
 this._alertY.showAlert({
  buttons:["取消", "确认"] 按钮文字 默认值
  prompt:true, 是否需要输入框
  content:"内容",
  onTap(v){
    console.log(v);
    }
  });
 */
